﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;

namespace BZV.Foundation.Business
{
    public class LotteryQueryControl:Control
    {
        // 事件定义
        public EventHandler OnIntoWaiteHandler;                // 进入开奖等待阶段
        public EventHandler OnIntoCountDownHandler;            // 进入倒计时阶段
        public EventHandler OnIntoGetTimeHandler;              // 进入到最后的获取阶段。
        public EventHandler OnOpenHandler;                     // 开奖

        // 定义变量
        public QueryCode m_code;

        public LotteryQueryControl(String strID)
        {
            m_code = new QueryCode(strID);
        }

        public void Load()
        {
            m_code.OnOpen += new EventHandler(OnOpen);
            m_code.OnIntoWaite += new EventHandler(OnIntoWait);
            m_code.OnIntoCountDown += new EventHandler(OnCountDown);
            m_code.OnIntoGetTime += new EventHandler(OnGetTme);

            // 开始查询
            m_code.Start();
        }

        void OnOpen(object sender, EventArgs e)
        {
            new Thread((ThreadStart)delegate
            {
                try
                {
                    this.Invoke((EventHandler)delegate
                    {
                        try
                        {
                            if (OnOpenHandler != null)
                            {
                                OnOpenHandler(sender, e);
                            }
                        }
                        catch (System.Exception ex)
                        {
                        	
                        }
                    });
                }
                catch (System.Exception ex)
                {
                	
                }

            }
             ).Start();
        }

        void OnIntoWait(object sender, EventArgs e)
        {
            
            new Thread((ThreadStart)delegate
            {
                try
                {
                    this.Invoke((EventHandler)delegate
                    {
                        try
                        {
                            if (OnIntoWaiteHandler != null)
                            {
                                OnIntoWaiteHandler(sender, e);
                            }
                        }
                        catch (System.Exception ex)
                        {
                            return;
                        }

                    });
                }
                catch (System.Exception ex)
                {
                	
                }

            }
             ).Start();
        }

        void OnCountDown(object sender, EventArgs e)
        {
            new Thread((ThreadStart)delegate
            {
                try
                {
                    this.Invoke((EventHandler)delegate
                    {
                        try
                        {
                            if (OnIntoCountDownHandler != null)
                            {
                                OnIntoCountDownHandler(sender, e);
                            }
                        }
                        catch (System.Exception ex)
                        {
                            return;
                        }

                    });
                }
                catch (System.Exception ex)
                {
                	
                }

            }
             ).Start();
        }

        void OnGetTme(object sender, EventArgs e)
        {
            new Thread((ThreadStart)delegate
            {
                try
                {
                    this.Invoke((EventHandler)delegate
                    {
                        if (OnIntoGetTimeHandler != null)
                        {
                            OnIntoGetTimeHandler(sender, e);
                        }
                    });
                }
                catch (System.Exception ex)
                {
                	
                }
                

            }
             ).Start();

        }
    }
}
